package com.jams.goodox.activity.mine.red;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.activity.common.SimpleHtmlActivity;
import com.jams.goodox.adapter.CustomFragmentPagerAdapter;
import com.jams.goodox.constant.H5UrlConstants;
import com.jams.goodox.utils.StyleUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * 红包页：个人&企业红包
 * by hgz
 */
public class MineRedPacketsActivity extends BaseActivity {

    @Bind(R.id.tabLayout)
    TabLayout tabLayout;
    @Bind(R.id.viewPager)
    ViewPager viewPager;

    private MineRedPackets1Fragment fragment1;
    private MineRedPackets2Fragment fragment2;
    private MineRedPackets3Fragment fragment3;
    private List<Fragment> fragmentList;

    private boolean isMinePicket;//是否是个人红包

    public final static String NONE_RED = "暂无红包";

    @Override
    protected int getLayoutId() {
        return R.layout.mine_red;
    }

    @Override
    protected void init() {
        isMinePicket = getIntent().getBooleanExtra("isMinePicket", true);
        StyleUtil.titleBackKeyWithRightTextViewListener(this, isMinePicket ? "我的红包" : "企业红包", "红包说明", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle b = new Bundle();
                b.putString(SimpleHtmlActivity.URL, H5UrlConstants.H5_Agreement);
                b.putString(SimpleHtmlActivity.TITLE, "红包说明");
                qBackToActivity(SimpleHtmlActivity.class, b);
            }
        });


        fragment1 = MineRedPackets1Fragment.getInstance(isMinePicket);
        fragment2 = MineRedPackets2Fragment.getInstance(isMinePicket);
        fragment3 = MineRedPackets3Fragment.getInstance(isMinePicket);

        fragmentList = new ArrayList<>();
        List<String> tabsTitle = new ArrayList<>();
        fragmentList.add(fragment1);
        tabsTitle.add("可使用");
        fragmentList.add(fragment2);
        tabsTitle.add("已使用");
        fragmentList.add(fragment3);
        tabsTitle.add("已过期");

        viewPager.setAdapter(new CustomFragmentPagerAdapter(getSupportFragmentManager(), tabsTitle, fragmentList));

        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

        viewPager.setOffscreenPageLimit(2);
    }
}

